/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.etrs.formathlon.entity.formation;

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import net.etrs.formathlon.entity.utils.ComparableEvenThoughUnpersisted;
import org.apache.commons.lang.time.DateUtils;

/**
 * Entité symbolisant une séance dans le cadre d'une session de formation.
 * @author OPIF
 */
@Entity
public class Seance extends ComparableEvenThoughUnpersisted<Seance> {
    
    
    private static final long serialVersionUID = 1L;
    
    /**
     * Identifiant.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    /**
     * Date de debut de la séance.
     */
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date dateHeureDebut;
    
    /**
     * Durée de la séance.
     */
    private int duree;
    
    /**
     * Session ou se place la séance.
     */
    @ManyToOne
    private Session session;
    
    /**
     * Attribut technique pour ne pas supprimer de la base.
     */
    private boolean archive;

    @Override
    public Long getId() {
        return id;
    }

    /**
     * Setter de l'id.
     * @param id 
     */
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return String.format("Session id=%d, dateHeureDebut=%s", id, dateHeureDebut.toString());
    }

    /**
     * @return the dateHeureDebut
     */
    public Date getDateHeureDebut() {
        return dateHeureDebut;
    }

    /**
     * @param dateHeureDebut the dateHeureDebut to set
     */
    public void setDateHeureDebut(Date dateHeureDebut) {
        this.dateHeureDebut = dateHeureDebut;
    }

    /**
     * @return the duree
     */
    public int getDuree() {
        return duree;
    }

    /**
     * @param duree the duree to set
     */
    public void setDuree(int duree) {
        this.duree = duree;
    }

    /**
     * @return the session
     */
    public Session getSession() {
        return session;
    }

    /**
     * @param session the session to set
     */
    public void setSession(Session session) {
        this.session = session;
    }

    /**
     * @return the dateHeureFin
     */
    public Date getDateHeureFin() {
        Date fin = DateUtils.addHours(dateHeureDebut, duree);
        return DateUtils.addMinutes(fin, -10);
    }

    /**
     * @return the archive
     */
    @Override
    public boolean isArchive() {
        return archive;
    }

    /**
     * @param archive the archive to set
     */
    @Override
    public void setArchive(boolean archive) {
        this.archive = archive;
    }
}
